﻿using System;
class MaxSeqOfEqualElements
{
    static void Main()
    {
        int lenght;
        int maxCount = 1;
        int count = 1;
        int number = 0;
        Console.Write("please enter the lenght of array: ");
        while (true)
        {
            try
            {
                lenght = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter lenght:");
            }
        }
        int[] theArray;
        theArray = new int[lenght];
        for (int i = 0; i < lenght; i++)
        {
            Console.Write("Please enter the {0} element of array: ", i);
            while (true)
            {
                try
                {
                    theArray[i] = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("Please re-enter element:");
                }
            }
        }
        for (int i = 0; i < (lenght - 1); i++)
        {
            if ((theArray[i] == theArray[i + 1]))
            {
                count++;
                if (i == lenght - 2)
                {
                    if (count > maxCount)
                    {
                        maxCount = count;
                        number = theArray[i];
                    }
                }
            }
            else
            {
                if (count > maxCount)
                {
                    maxCount = count;
                    number = theArray[i];
                    count = 1;
                }
            }
        }
        Console.WriteLine("Maximal sequence of elements are: {0}", maxCount);
        Console.Write("and the numbers are: ");
        for (int i = 0; i < maxCount; i++)
        {
            Console.Write("{0} ", number);
        }
        Console.ReadLine();
    }
}

